import router from './routers'
import {
  Notification
} from 'element-ui'

const whiteList = ['/login']

router.beforeEach((to, from, next) => {
  const token = window.sessionStorage.getItem('uuid')
  console.log(token)
  if (token) {
    if (to.path === '/login') {
      next({
        path: '/'
      })
    } else {
      next()
    }
  } else {
    if (whiteList.indexOf(to.path) !== -1) {
      next()
    } else {
      Notification.error({
        title: '用户未登录',
        duration: 3000
      })
      next({
        path: '/login'
      })
    }
  }
})
